/*
 * ConnectButtonListener.cpp
 *
 *  Created on: Oct 24, 2011
 *      Author: gonzalo
 */

#include "ConnectButtonListener.h"
using namespace std;
ConnectButtonListener::ConnectButtonListener(Textbox* userName, Textbox* host) {
	this->userName = userName;
	this->host = host;
}

ConnectButtonListener::~ConnectButtonListener() {
}

void ConnectButtonListener::execute() {
	std::string user = this->userName->getInput();
	std::string host = this->host->getInput();
	if ((host.length()!=0)&&(user.length()!=0)){
	pushEventsToOpenEditSceneWindow(user, host);}
	else
		{cout<<"No ha elegido su nombre de jugador o su host "<<endl;}
}

//TODO , esto no deberia estar aca...
void ConnectButtonListener::pushEventsToOpenEditSceneWindow(std::string user,
		std::string host) {

	SDL_Event event1;
	event1.type = SDL_USEREVENT;
	event1.user.code = CONNECT;
	event1.user.data1 = new std::string(host);
	event1.user.data2 = new std::string(user);
	SDL_PushEvent(&event1);

	SDL_Event event2;
	event2.type = SDL_VIDEORESIZE;
	event2.resize.w = PLAY_WIDTH_RESOLUTION;
	event2.resize.h = PLAY_HEIGHT_RESOLUTION;
	SDL_PushEvent(&event2);
}

